package ua.org.nuos.sdms.clientgui.client.handlers;

import com.vaadin.ui.*;
import ua.org.nuos.sdms.clientgui.client.components.factory.SeparatorFactory;
import ua.org.nuos.sdms.clientgui.client.components.window.AbstractWindow;
import ua.org.nuos.sdms.clientgui.client.events.ShowRegisterNewUserLayoutEvent;
import ua.org.nuos.sdms.clientgui.client.listeners.ShowRegisterNewUserLayoutListener;
import ua.org.nuos.sdms.clientgui.client.view.LoginWindow;
import ua.org.nuos.sdms.clientgui.client.view.RegisterNewUserComponent;
import ua.org.nuos.sdms.clientgui.server.AppProxy;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 01.04.12
 * Time: 18:05
 * To change this template use File | Settings | File Templates.
 */
public class ShowRegisterNewUserLayoutHandler implements ShowRegisterNewUserLayoutListener {

    private static final String REGISTRATION_HEIGHT = "526";

    @Override
    public void show(ShowRegisterNewUserLayoutEvent event) {
        VerticalLayout registration = new RegisterNewUserComponent() {
            protected Layout getButtonsLayout() {
                HorizontalLayout superLayout = (HorizontalLayout) super.getButtonsLayout();
                close.setVisible(false);
                superLayout.setSpacing(false);
                return superLayout;
            }
        }.getContent();
        registration.addComponent(SeparatorFactory.getHorizontal(), 0);
        registration.addComponent(new Label("<b>Заполните данные для регстрации</b>", Label.CONTENT_XHTML), 1);

        ComponentContainer layout = AppProxy.getInstance().getComponentLocator().getContainer(LoginWindow.REGISTRATION_LAYOUT_ID);
        layout.removeAllComponents();
        layout.addComponent(registration);
        AbstractWindow window = AppProxy.getInstance().getComponentLocator().getWindow(LoginWindow.ID);
        window.getWindow().setHeight(REGISTRATION_HEIGHT);
    }
}
